//
//  RMMTabBarViewController.m
//  Romomo
//
//  Created by puman on 16/9/30.
//  Copyright © 2016年 mazegong. All rights reserved.
//

#import "RMMTabBarViewController.h"
#import "RMMHomeViewController.h"
#import "RMMMineViewController.h"
#import "RMMShoppingCartViewController.h"
#import "RMMOrderViewController.h"
#import "RMMNavigationViewController.h"

@interface RMMTabBarViewController ()

@end

@implementation RMMTabBarViewController
{
    RMMShoppingCartViewController *_cartVC;
    RMMNavigationViewController *_twoVC;
}
- (void)dealloc{
    NS_REM(@"ADDSHOPMARTSUCCESS", nil);
    NS_REM(@"SHOPMARTCLEAN", nil);
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.tabBar.tintColor = [UIColor blackColor];
//    self.tabBar.barTintColor = [UIColor blackColor];
    [self.tabBarController.tabBar setTintColor:[UIColor whiteColor]];
//    [self addViewControllerClass:[RMMHomeViewController class] title:@"首页" imageName:@"home-1@3x" selectImageName:@""];
//    [self addViewControllerClass:[RMMShoppingCartViewController class] title:@"购物车" imageName:@"cart-1@3x" selectImageName:@""];
//    [self addViewControllerClass:[RMMOrderViewController class] title:@"订单" imageName:@"order-1@3x" selectImageName:@""];
//    [self addViewControllerClass:[RMMMineViewController class] title:@"我" imageName:@"personal-1@3x" selectImageName:@""];
    _cartVC = [[RMMShoppingCartViewController alloc] init];
    RMMHomeViewController *homeVC = [[RMMHomeViewController alloc] init];
    RMMOrderViewController *orderVC = [[RMMOrderViewController alloc] init];
    RMMMineViewController *mineVC = [[RMMMineViewController alloc] init];
    RMMNavigationViewController *oneVC = [[RMMNavigationViewController alloc] initWithRootViewController:homeVC];
    
    oneVC.tabBarItem.image = [UIImage imageNamed:@"home-1@3x"];
    oneVC.tabBarItem.selectedImage = [UIImage imageNamed:@"home-2@3x"];
    oneVC.tabBarItem.title = @"首页";
    homeVC.navigationItem.title = @"首页";
    
    _twoVC = [[RMMNavigationViewController alloc] initWithRootViewController:_cartVC];
    _twoVC.tabBarItem.image = [UIImage imageNamed:@"cart-1@3x"];
    _twoVC.tabBarItem.selectedImage = [UIImage imageNamed:@"cart-2@3x"];
    _twoVC.tabBarItem.title = @"购物车";
    _cartVC.navigationItem.title = @"购物车";
    
    RMMNavigationViewController *threeVC = [[RMMNavigationViewController alloc] initWithRootViewController:orderVC];
    threeVC.tabBarItem.image = [UIImage imageNamed:@"order-1@3x"];
    threeVC.tabBarItem.selectedImage = [UIImage imageNamed:@"order-2@3x"];
    threeVC.tabBarItem.title = @"订单";
    orderVC.navigationItem.title = @"全部订单";
    
    RMMNavigationViewController *fourVC = [[RMMNavigationViewController alloc] initWithRootViewController:mineVC];
    fourVC.tabBarItem.image = [UIImage imageNamed:@"personal-1@3x"];
    fourVC.tabBarItem.selectedImage = [UIImage imageNamed:@"personal-2@3x"];
    fourVC.tabBarItem.title = @"我";
    mineVC.navigationItem.title = @"我";
    self.selectedIndex = 0;
//    oneVC.navigationBar.translucent = kWhiteColor;
//    _twoVC.navigationBar.backgroundColor = kWhiteColor;
//    threeVC.navigationBar.backgroundColor = kWhiteColor;
//    fourVC.navigationBar.backgroundColor = kWhiteColor;
   // self.delegate = self;
    [self setViewControllers:@[oneVC,_twoVC,threeVC,fourVC]];
    NSString *backValue = [[RMMFileManager shareHandle] getValeForKey:@"SHOPMARTCOUNT"];
    if ([backValue isEqualToString:@"0"]) {
        backValue = nil;
    }
    _twoVC.tabBarItem.badgeValue = backValue;
    NS_ADD(backValue, @"ADDSHOPMARTSUCCESS", nil);
    NS_ADD(backNil, @"SHOPMARTCLEAN", nil);
}
- (void)backNil{
    _twoVC.tabBarItem.badgeValue = nil;
}
- (void)backValue{
    NSString *backValue = [[RMMFileManager shareHandle] getValeForKey:@"SHOPMARTCOUNT"];
    _twoVC.tabBarItem.badgeValue = backValue;
}
- (void)addViewControllerClass:(Class)class title:(NSString *)title imageName:(NSString *)imageName selectImageName:(NSString *)selectImageName
{
    UIViewController *viewVC = [[class alloc]init];
    RMMNavigationViewController *naVC = [[RMMNavigationViewController alloc] initWithRootViewController:viewVC];
    naVC.navigationBar.translucent = NO;
    naVC.tabBarItem.title = title;
    naVC.tabBarItem.image = [UIImage imageNamed:imageName];
    //naVC.tabBarItem.selectedImage = [UIImage imageNamed:selectImageName];
    naVC.navigationBar.barTintColor = [UIColor whiteColor];
    viewVC.navigationItem.title = title;
    [naVC.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor blackColor]}];
    [self addChildViewController:naVC];
}
//- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
//    viewController.tabBarItem.badgeValue = nil;
//}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
